package com.wzq.str;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class ChinaNum {

    private final static Map<Integer,Character> m = new HashMap<Integer, Character>();
    static {
        m.put(0,'零');m.put(1,'一');m.put(2,'二');m.put(3,'三');m.put(4,'四');m.put(5,'五');
        m.put(6,'六');m.put(7,'七');m.put(8,'八');m.put(9,'九');m.put(10,'十');m.put(100,'百');
        m.put(1000,'千');m.put(10000,'万');m.put(100000000,'亿');//m.put(,'');m.put(,'');m.put(,'');
    }

    public static LinkedList<Character> intToList(int val){

        LinkedList<Character> rst =null;
        if (val >= 100000000){
            rst = intToListLTYi(val/100000000);
            rst.addLast(m.get(100000000));
            if(val%100000000 > 0 && val%100000000 < 10000000 ){
                rst.addLast(m.get(0));
            }
            if(val%100000000 > 0){
                rst.addAll(intToListLTYi(val%100000000));
            }
        }else{
            rst = intToListLTYi(val);
        }
        return rst;
    }

    public static LinkedList<Character> intToListLTYi(int val){

        LinkedList<Character> rst =null;
        if(val >= 10000){
            rst = intToListLTWan(val/10000);
            rst.addLast(m.get(10000));
            if(val%10000 > 0 && val%10000 < 1000 ){
                rst.addLast(m.get(0));
            }
            if(val%10000 > 0){
                rst.addAll(intToListLTWan(val%10000));
            }
        }else{
            rst = intToListLTWan(val);
        }
        return rst;
    }

    public static LinkedList<Character> intToListLTWan(int val){
        LinkedList<Character> rst = new LinkedList<Character>();

        for (int n=1;val/n>0; n *= 10){
            int v = val/n%10;
            if(v != 0 && n != 1){
                rst.addFirst(m.get(n));
            }
            if(v != 0 || (rst.size() != 0 && rst.getFirst() != m.get(0))){
                rst.addFirst(m.get(v));
            }
        }
        if(val >=10 && val<20){
            rst.pollFirst();
        }
        return rst;
    }

    public static void main(String[] args) {
        for (int i=10000000;i<10000100;i++){
            System.out.println(charListToStr(intToList(i)));
        }
    }

    public static String charListToStr(List<Character> l){
        StringBuilder sb = new StringBuilder();
        for (Character c:l){
            sb.append(c);
        }
        return sb.toString();
    }
}
